package com.demo.data;
import com.demo.model.ResultEnum;

/* 统一返回实体类 */
public class Result<T> {


    private Integer code;
    private String message;
    private T data;

    public static Result response(ResultEnum em){
        Result result = new Result(em.getCode() , em.getMessage());
        return result;
    }

    public static Result ok(){
        Result result = new Result(ResultEnum.SUCCESS.getCode() , ResultEnum.SUCCESS.getMessage());
        return result;
    }
    public static Result nook(){
        Result result = new Result(ResultEnum.ERROR.getCode() , ResultEnum.ERROR.getMessage());
        return result;
    }

    public Result() {
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public Result setMessage(String message) {
        this.message = message;
        return null;
    }

    public Result(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Result(T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public T getData() {
        return data;
    }

    public Result setData(T data) {
        this.data = data;
        return this;
    }
}
